package cn.edu.scau.cmi.linjinyong.singleton;

import javafx.beans.Observable;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;

public class SingletonController {

    @FXML
    private TextField charimanNameField;
    @FXML
    private TableView<Data> chairmanTable;
    @FXML
    private TableColumn<Data, String> nameColumn;
    @FXML
    private TableColumn<Data, String> objectColumn;
    @FXML
    private Label result;

    private ObservableList<Data> chairmanDatas;

    @FXML
    private void initialize() {
        chairmanDatas = FXCollections.observableArrayList();
        nameColumn.setCellValueFactory(new PropertyValueFactory("name"));
        objectColumn.setCellValueFactory(new PropertyValueFactory("object"));
        chairmanTable.setItems(chairmanDatas);
    }

    @FXML
    private void createChairman() {
        if (charimanNameField.getText() != null && !"".equals(charimanNameField.getText())) {
            Chairman chairman = Chairman.createChairman(charimanNameField.getText());
            chairmanDatas.add(new Data(chairman.getName(), chairman.toString()));
            chairmanTable.setItems(chairmanDatas);
            result.setText("创建成功");
        }else {
            result.setText("名字不能为空");
        }
    }
}
